package com.hbpu.encap.extend;

import java.util.Scanner;

public class Account {
    private String name;
    private int balance;
    private String password;

    public Account() {
    }

    public Account(String name, int balance, String password) {
        setName(name);
        setBalance(balance);
        setPassword(password);
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        if (name.length() == 2 || name.length() == 3 || name.length() == 4) {
            this.name = name;
        } else {
            System.out.println("姓名长度必须在2-4之间！默认值：hh");
            this.name = "hh";
        }
    }

    public int getBalance() {
        return balance;
    }

    public void setBalance(int balance) {
        if (balance > 20) {
            this.balance = balance;
        } else {
            System.out.println("余额必须大于20！默认值：30");
            this.balance = 30;
        }
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        if (password.length() == 6) {
            this.password = password;
        } else {
            System.out.println("密码长度必须为：6，默认值：123456");
            this.password = "123456";
        }
    }

    public void info() {
        System.out.print("请输入密码：");
        Scanner scanner = new Scanner(System.in);
        String passwordIn = scanner.next();
        if (passwordIn.length() == 6 && passwordIn.equals(this.password)) {
            System.out.println("姓名：" + name + " 余额：" + balance + " 密码：" + password);
        } else {
            System.out.println("密码错误，无法访问！");
            return;
        }
    }
}
